package graphics.server;

/**
 * This class creates Agents
 */
public class SingleAgent {

	private String name;			// Agent name
	private String color;			// Agent color
	private String orientation;		// Agent orientation -North / South / East / West
	private int location;			// Agent location in the grid
	private int boardXSize;			// grid X size
	//private int boardYSize;			// grid Y size

	/**
	 * @param name
	 * @param Color
	 * @param orientation
	 * @param location
	 * @param xSize
	 * @param ySize
	 *
	 * Constructor for class Agent
	 */
	public SingleAgent(String name,String Color,String orientation,
			int location,int xSize,int ySize){
		this.name=name;
		this.color=Color;
		this.orientation=orientation;
		this.location =location;
		this.boardXSize=xSize;
		//this.boardYSize=ySize;
	}
	/**
	 * @return Returns the Agent color.
	 */
	public String getColor() {
		return color;
	}
	/**
	 * @return Returns the Agent location.
	 */
	public int getLocation() {
		return location;
	}
	/**
	 * @return Returns the name of the Agent.
	 */
	public String getName() {
		return name;
	}
	/**
	 * @return Returns the Agent orientation.
	 */
	public String getOrientation() {
		return orientation;
	}

	/**
	 *
	 * @return the cell to move forward
	 *
	 * This procedure finds the cell to move forward to.
	 * (It depends on the orientation)
	 */
	public int getNewCell(){
		int newCell = this.getLocation();
		if (orientation.compareToIgnoreCase("North")==0)
			newCell -=boardXSize;
		else if(orientation.compareToIgnoreCase("East")==0)
			newCell += 1;
		else if(orientation.compareToIgnoreCase("West")==0)
			newCell -= 1;
		else if(orientation.compareToIgnoreCase("South")==0)
			newCell +=boardXSize;
		return newCell;
	}

	/**
	 *
	 * @param move
	 * @return the next orientation
	 *
	 * This procedure finds the orientation after the move.
	 * (It depends on the previous orientation)
	 */
	public String getNewOrientation(String move){
		String newOrientation = orientation;
		if(move.compareTo("RIGHT")==0){
			if (orientation.compareToIgnoreCase("North")==0)
				newOrientation ="East";
			else if(orientation.compareToIgnoreCase("East")==0)
				newOrientation = "South";
			else if(orientation.compareToIgnoreCase("West")==0)
				newOrientation = "North";
			else if(orientation.compareToIgnoreCase("South")==0)
				newOrientation ="West";
		}
		else if(move.compareTo("LEFT")==0){
			if (orientation.compareToIgnoreCase("North")==0)
				newOrientation ="West";
			else if(orientation.compareToIgnoreCase("East")==0)
				newOrientation = "North";
			else if(orientation.compareToIgnoreCase("West")==0)
				newOrientation = "South";
			else if(orientation.compareToIgnoreCase("South")==0)
				newOrientation ="East";
		}
		return newOrientation;
	}
	/**
	 * @param location  - The location to set.
	 */
	public void setLocation(int location) {
		this.location = location;
	}
	/**
	 * @param orientation  - The orientation to set.
	 */
	public void setOrientation(String orientation) {
		this.orientation = orientation;
	}
}
